//
//  SDMeViewController.swift
//  Seed
//
//  Created by Samuel on 2017/6/5.
//  Copyright © 2017年 RedSoft. All rights reserved.
//

import UIKit

class SDMeViewController: YMBaseViewController,UITableViewDelegate, UITableViewDataSource {

    
    @IBOutlet weak var tableView: UITableView!
    
    private var options = [
        ["title":"消息通知","icon":"news"],
        ["title":"邀请好友一起学习","icon":"invite"],
        ["title":"观看记录","icon":"news"],
        ["title":"我的下载","icon":"download"],
    ]
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        configUI()
    }
    
    func configUI() {
        tableView.delegate = self
        tableView.dataSource = self
        self.automaticallyAdjustsScrollViewInsets = false
        //导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem.init(image: #imageLiteral(resourceName: "setting"), style: .plain, target: self, action: #selector(settingClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem.init(image: #imageLiteral(resourceName: "listening"), style: .plain, target: self, action: #selector(listenClick))
        
    }

    //#MARK: Private Methods
    func settingClick() {
        //清空账号信息
        SDAccountTool.shared.clearAccount()
        //退出登录状态
        appDelegate.setLoginStatus(false)
    }
    
    func listenClick() {
        
    }
    
    @IBAction func hasBuyCourseClick(_ sender: UIButton) {
        
    }
    
    @IBAction func studyListClick(_ sender: UIButton) {
        
    }
    
    //#MARK: UITableViewDataSource
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return options.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "MeOption", for: indexPath) as! SDMeOptionCell
        
        let option = options[indexPath.row]
        cell.iconView.image = UIImage.init(named: option["icon"]!)
        cell.optionLabel.text = option["title"]
        if indexPath.row == 0 {
            cell.notiCountLabel.isHidden = false
        }
        if indexPath.row == 1 {
            cell.inviteLabel.isHidden = false
        }
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 51
    }
}
